package zhaolu.com.example.Delicacy.Utils;

import zhaolu.com.example.Delicacy.Activity.FragmentActivity;
import zhaolu.com.example.Delicacy.Activity.MainActivity;
import zhaolu.com.example.Delicacy.Entity.Customer;
import zhaolu.com.example.Delicacy.Entity.HistoryBean;
import zhaolu.com.example.Delicacy.Entity.Order;
import zhaolu.com.example.Delicacy.MySQL.OrderDAO;
import zhaolu.com.example.Delicacy.R;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import java.sql.BatchUpdateException;
import java.util.List;

import zhaolu.com.example.Delicacy.Entity.ItemBean;

public class HistoryAdapter extends BaseAdapter {
    private List<HistoryBean> beanList;
    private LayoutInflater layoutInflater;
    private Context context;

    public HistoryAdapter(Context context, List<HistoryBean> beanList) {
        this.context = context;
        this.beanList = beanList;
        layoutInflater = LayoutInflater.from(this.context);
    }

    @Override
    public int getCount() {
        return beanList.size();
    }

    @Override
    public Object getItem(int i) {
        return beanList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        // 创建视图控件
        ViewHolder viewHolder = new ViewHolder();
        if (view == null) {
            view = layoutInflater.inflate(R.layout.history_menu, viewGroup, false);
            TextView textView1 = view.findViewById(R.id.history_name);
            TextView textView2 = view.findViewById(R.id.history_time);
            TextView textView3 = view.findViewById(R.id.history_amount);
            viewHolder.textView1 = textView1;
            viewHolder.textView2 = textView2;
            viewHolder.textView3 = textView3;
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        // 填充数据
        HistoryBean itemBean = beanList.get(i);
        viewHolder.textView1.setText(itemBean.getFoodName());
        String str1 = "下单时间：" + itemBean.getOrderTime();
        viewHolder.textView2.setText(str1);
        String str2 = "订单金额：" + String.valueOf(itemBean.getOrderAmount());
        viewHolder.textView3.setText(str2);
        return view;
    }

    class ViewHolder {
        TextView textView1;
        TextView textView2;
        TextView textView3;
    }

}
